package com.imooc.productviewservicefeign.controller;

import com.imooc.productviewservicefeign.pojo.product;
import com.imooc.productviewservicefeign.service.productservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @program: springcloud_demo
 * @description:
 * @author: ZhangKai
 * @create: 2019-09-17 21:37
 **/

@Controller
@RefreshScope
public class productcontroller {

    @Autowired
    productservice productservice;

    @Value("${version}")
    private String version;

    @RequestMapping("/products")
    public Object products(ModelMap map){
        List<product> ps = productservice.listProducts();
        map.addAttribute("version", version);
        map.addAttribute("ps", ps);
        return "products";
    }
}
